package com.authine.cloudpivot.ext.controller;

import com.authine.cloudpivot.ext.service.OaToFacade;
import com.authine.cloudpivot.ext.task.TaskDelayedManager;
import com.authine.cloudpivot.web.api.controller.base.BaseController;
import com.authine.cloudpivot.web.api.view.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @Author hxd
 * @Date 2021/11/26 13:39
 * @Description
 **/
@RestController
@RequestMapping("/public/oaTodo")
@Slf4j
public class MszqOaTodoController extends BaseController {


    @Autowired
    private OaToFacade oaToFacade;


    @GetMapping("bizId")
    public ResponseResult reSend(@RequestParam String bizId){

        Map<String, Object> rstMap = oaToFacade.reSend(getUserId(), bizId);
        String code = MapUtils.getString(rstMap,"code");

        if("0".equals(code)){
            return getOkResponseResult(null,"ok");
        }else{
            String msg = MapUtils.getString(rstMap,"msg");
            return getErrResponseResult(-1l, msg);
        }

    }

    @GetMapping("reloadOaTodoSetting")
    public void reloadOaTodoSetting(){

        try {
            TaskDelayedManager.put( () -> oaToFacade.loadOaTodoSetting(),7, TimeUnit.SECONDS);
        }catch (Exception e){
            log.error("加载OA应用配置异常:{}",e);
        }


    }

}
